// Button group
//
// A button group is a series of buttons laid out next to each other, all part
// of one visual button, but separated by rules to be separate.

.BtnGroup {
  display: inline-block;
  vertical-align: middle;

  @include clearfix();

  // Proper spacing for multiple button groups (a la, gollum editor)
  + .BtnGroup,
  + .btn {
    margin-left: var(--base-size-4);
  }
}

.BtnGroup-item {
  position: relative;
  float: left;
  border-right-width: 0;
  border-radius: 0;

  &:first-child {
    // stylelint-disable-next-line primer/borders
    border-top-left-radius: $border-radius;
    // stylelint-disable-next-line primer/borders
    border-bottom-left-radius: $border-radius;
  }

  &:last-child {
    // stylelint-disable-next-line primer/borders
    border-right-width: $border-width;
    // stylelint-disable-next-line primer/borders
    border-top-right-radius: $border-radius;
    // stylelint-disable-next-line primer/borders
    border-bottom-right-radius: $border-radius;
  }

  &.selected,
  &[aria-selected='true'],
  &:focus,
  &:active,
  &:hover {
    // stylelint-disable-next-line primer/borders
    border-right-width: $border-width;

    + .BtnGroup-item,
    + .BtnGroup-parent .BtnGroup-item {
      border-left-width: 0;
    }
  }
}

.BtnGroup-parent {
  float: left;

  &:first-child .BtnGroup-item {
    // stylelint-disable-next-line primer/borders
    border-top-left-radius: $border-radius;
    // stylelint-disable-next-line primer/borders
    border-bottom-left-radius: $border-radius;
  }

  &:last-child .BtnGroup-item {
    // stylelint-disable-next-line primer/borders
    border-right-width: $border-width;
    // stylelint-disable-next-line primer/borders
    border-top-right-radius: $border-radius;
    // stylelint-disable-next-line primer/borders
    border-bottom-right-radius: $border-radius;
  }

  .BtnGroup-item {
    border-right-width: 0;
    border-radius: 0;
  }

  &.selected,
  &[aria-selected='true'],
  &:focus,
  &:active,
  &:hover {
    .BtnGroup-item {
      // stylelint-disable-next-line primer/borders
      border-right-width: $border-width;
    }

    + .BtnGroup-item,
    + .BtnGroup-parent .BtnGroup-item {
      border-left-width: 0;
    }
  }
}

// ensure that the focus ring sits above the adjacent buttons
.BtnGroup-item,
.BtnGroup-parent {
  &:focus,
  &:active {
    z-index: 1;
  }
}
